//
//  LGSijiHomeViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/24.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCiTangHomeViewController.h"
#import "LGCiTangHomeTableViewCell.h"
#import "LGCiTangDetailViewController.h"

@interface LGCiTangHomeViewController ()
@property(nonatomic, strong) UISegmentedControl                     *segement;
@end

@implementation LGCiTangHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"宗祠祠堂";
    [self configSubView];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"icon_搜索"]];
   
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 20)];
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 156)];
    bannerImageView.image = [UIImage imageNamed:@"祠堂banner"];
    [header addSubview:bannerImageView];
    
    CGFloat segementWith = (UIScreenWidth - 40)/4;
    self.segement = [[UISegmentedControl alloc] initWithItems:@[@"最新祭拜",@"最新祠堂",@"兴旺排行",@"同宗祠堂"]];
    self.segement.frame = CGRectMake(20, 15 + bannerImageView.bottom, segementWith * 4, 44);
    self.segement.tintColor = TM_redColor;
    self.segement.selectedSegmentIndex = 0;
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateSelected];
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
    [self.segement addTarget:self action:@selector(onSelctedSegement:) forControlEvents:UIControlEventValueChanged];
    [header addSubview:self.segement];
    
    header.height = self.segement.bottom + 15;
    self.tableView.tableHeaderView = header;
    
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGCiTangHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 44;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * view = [TMUtils headerViewWithTitle:@"推荐陵园"];
    return view;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGCiTangHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGCiTangHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.navigationController pushViewController:[LGCiTangDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{

}
- (void)onSelctedSegement:(UISegmentedControl*)sender{
    
}
@end

